package com.inforich.web.controller.projectManage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.common.utils.poi.ExcelUtil;
import com.inforich.projectManage.domain.ProjectRubbishReport;
import com.inforich.projectManage.dto.ProjectApproveDTO;
import com.inforich.projectManage.service.IProjectRubbishReportService;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 固废排放计划申报Controller
 *
 * @author hjm
 * @date 2022-10-29
 */
@RestController
@RequestMapping("/projectManage/projectReport")
public class ProjectRubbishReportController extends BaseController {

  @Autowired
  private IProjectRubbishReportService projectRubbishReportService;

  /**
   * 查询固废排放计划申报列表
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectReport:list')")
  @GetMapping("/list")
  public Page<ProjectRubbishReport> list(Page<ProjectRubbishReport> page,
      ProjectRubbishReport projectRubbishReport) {
    Map<String, Object> map = beanToMap(projectRubbishReport);
    projectRubbishReportService.pageProjectRubbishReport(page, map);
    return page;
  }


  /**
   * 导出固废排放计划申报列表
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectReport:export')")
  @Log(title = "固废排放计划申报", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, ProjectRubbishReport projectRubbishReport) {
    Map<String, Object> map = beanToMap(projectRubbishReport);
    List<ProjectRubbishReport> list = projectRubbishReportService.listProjectRubbishReport(map);
    ExcelUtil<ProjectRubbishReport> util = new ExcelUtil<ProjectRubbishReport>(
        ProjectRubbishReport.class);
    util.exportExcel(response, list, "固废排放计划申报数据");
  }

  /**
   * 获取固废排放计划申报详细信息
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectReport:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") String id) {
    return AjaxResult.success(projectRubbishReportService.getProjectRubbishReportById(id));
  }

  /**
   * 新增固废排放计划申报
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectReport:add')")
  @Log(title = "固废排放计划申报", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody ProjectRubbishReport projectRubbishReport) {
    return toAjax(projectRubbishReportService.save(projectRubbishReport));
  }

  /**
   * 修改固废排放计划申报
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectReport:edit')")
  @Log(title = "固废排放计划申报", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody ProjectRubbishReport projectRubbishReport) {
    return toAjax(projectRubbishReportService.updateById(projectRubbishReport));
  }

  /**
   * 删除固废排放计划申报
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectReport:remove')")
  @Log(title = "固废排放计划申报", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable String[] ids) {
    return toAjax(projectRubbishReportService.removeByIds(Arrays.asList(ids)));
  }

  /**
   * 审批
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectReport:approve')")
  @PostMapping("/approve")
  public AjaxResult approve(@Validated @RequestBody ProjectApproveDTO projectApproveDTO) {
    return projectRubbishReportService.approve(projectApproveDTO);
  }
}
